﻿package com.gengine.resource.loader
{
    import com.gengine.debug.*;
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;

    public class SWFLoader extends BaseLoader
    {
        private var _clip:Sprite;
        private var _appDomain:ApplicationDomain;

        public function SWFLoader()
        {
            return;
        }// end function

        override public function getClass() : Class
        {
            return SWFLoader;
        }// end function

        public function get clip() : Sprite
        {
            return this._clip;
        }// end function

        public function get appDomain() : ApplicationDomain
        {
            return this._appDomain;
        }// end function

        public function getExportedAsset(param1:String) : Object
        {
            if (this._appDomain == null)
            {
                throw new Error("not initialized");
            }
            var _loc_2:* = this.getAssetClass(param1);
            if (_loc_2 != null)
            {
                return new _loc_2;
            }
            return null;
        }// end function

        public function getAssetClass(param1:String) : Class
        {
            if (this._appDomain == null)
            {
                throw new Error("not initialized");
            }
            if (this._appDomain.hasDefinition(param1))
            {
                return this._appDomain.getDefinition(param1) as Class;
            }
            return null;
        }// end function

        public function findMaxFrames(param1:MovieClip, param2:int) : int
        {
            var _loc_4:MovieClip = null;
            var _loc_3:int = 0;
            while (_loc_3 < param1.numChildren)
            {
                
                _loc_4 = param1.getChildAt(_loc_3) as MovieClip;
                if (!_loc_4)
                {
                }
                else
                {
                    param2 = Math.max(param2, _loc_4.totalFrames);
                    this.findMaxFrames(_loc_4, param2);
                }
                _loc_3++;
            }
            return param2;
        }// end function

        public function advanceChildClips(param1:MovieClip, param2:int) : void
        {
            var _loc_4:MovieClip = null;
            var _loc_3:int = 0;
            while (_loc_3 < param1.numChildren)
            {
                
                _loc_4 = param1.getChildAt(_loc_3) as MovieClip;
                if (!_loc_4)
                {
                }
                else
                {
                    if (_loc_4.totalFrames >= param2)
                    {
                        _loc_4.gotoAndStop(param2);
                    }
                    this.advanceChildClips(_loc_4, param2);
                }
                _loc_3++;
            }
            return;
        }// end function

        override protected function onContentReady(param1) : Boolean
        {
            if (loaderInfo)
            {
                if (resourceInfo)
                {
                    resourceInfo.data = loaderInfo;
                }
                this._appDomain = loaderInfo.applicationDomain;
            }
            return param1 as Sprite != null;
        }// end function

        private function onUnloadHandler(event:Event) : void
        {
            if (resourceInfo)
            {
                Log.debug("unload:" + resourceInfo.name);
                if (loaderInfo)
                {
                    loaderInfo.removeEventListener(Event.UNLOAD, this.onUnloadHandler);
                }
            }
            return;
        }// end function

        override public function dispose() : void
        {
            super.dispose();
            return;
        }// end function

    }
}
